home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_01_02
/
clune.exe
/
MENU_DEM.C
< prev
next >
Wrap
Text File
|
1990-07-20
|
8KB
|
311 lines
/* menu_dem.c is a demonstration of the menu.c functions and how to use */
/* them. To compile, use Microsoft C LARGE MEMORY model. To link, use: */
/* LINK MENU_DEM,,,ERI_MENU MOUSE If you don't have MOUSE.LIB, you may: */
/* LINK MENU_DEM,,,ERI_MENU MOUS_SYS */
/* Written 8/89 by T. Clune. No rights reserved. Modified 9/89 to use */
/* mgets() and mgetch() in MENU instead of function pointers. */
/* Comments spruced up 7/90 by T Clune. */
#include <stdio.h>
#include <math.h> /* atoi() and atof() declarations */
/* my headers needed for this program */
#include "ansi.h" /* my ansi.sys macros */
#include "mouselib.h" /* my mouse.lib front-end functions */
#include "menu.h" /* the menu.c declarations and definitions */
#include "keys.h" /* my defined constants for key presses */
/* the functions in this file */
static void getfile_demo(), menu_options_demo();
static void mouse_sensitivity(), input_options();
static int single_file(), binary_choice();
void main()
{
/* the main menu choices */
static char *options[] =
{
"Quit",
"get_file() demo",
"Menu adjustments options"
};
/* ENTRIES is number of items in options[] above, CHOICE will be */
/* the subscript of options[] selected from the menu. */
int entries=3, choice;
/* check for mouse and driver presence. */
if(!m_install().status)
{
printf("Mouse or mouse.sys not found. Program aborting.\n");
exit(-1);
}
/* set the menu for selection by mouse or keyboard. */
mouse_flag_toggle(MOUSE_PLUS_KEYBOARD);
reset_menu(0); /* menu highlight starts out on first menu item */
for(;;)
{
CLS; /* clear screen. ANSI.SYS macro defined in ANSI.H */
/* print the title of the menu, centered and underlined */
print_headline("DEMONSTRATION PROGRAM MAIN MENU", 20, 1);
/* the heirarchical menu structure 'YOU ARE HERE:' aid */
pathprint("ROOT");
/* get a menu selection. single_file() is a */
/* boilerplate function defined in this file. */
choice=single_file(options, entries);
switch(choice) /* see the OPTION strings for meaning of choice */
{
case 0:
CLS;
exit(0);
case 1:
CLS;
getfile_demo();
reset_menu(choice); /* reset the highlight to show */
/* the last active selection from this menu */
break;
case 2:
CLS;
menu_options_demo();
reset_menu(choice);
break;
default:
break;
}
}
}
/* binary_choice() is a generic input for y/n-type responses, in which */
/* PRIMARY is the default value if <CR> or (assuming the mouse is active) */
/* right mouse button is pressed, and ALTERNATE is the other valid input. */
/* The prompt that is to be printed to explain the binary_choice() options */
/* is separate from this function. */
static int binary_choice(primary, alternate)
int primary, alternate;
{
int c;
primary=toupper(primary);
alternate=toupper(alternate);
while((c=(toupper(mgetch()))) != primary && c != alternate && c != CARRIAGE_RETURN)
error_msg();
if(c==CARRIAGE_RETURN)
c=primary;
return c;
}
/* getfile_demo() demonstrates get_file(). It displays a directory, from */
/* which you select a file, whose name is then printed on the screen as your */
/* selection. */
static void getfile_demo()
{
string_struc f; /* the get_file() struct, defined in menu.h */
int c;
CLS;
do
{
f=get_file();
if(f.error_flag != 0)
{
printf("Do you want to abort this function and return to the main menu (y/N)?\n");
c=binary_choice('N','Y');
if(c=='Y')
return;
}
}while(f.error_flag != 0);
printf("You selected %s\n", f.string);
printf("Press any key to return...");
mgetch();
}
/* input_options() is a menu for selecting what input device(s) will */
/* activate the menu selection */
static void input_options()
{
static char *options[] =
{
"Keyboard ONLY",
"Mouse ONLY",
"Mouse OR keyboard"
};
int choice, entries=3;
reset_menu(0);
CLS;
print_headline("INPUT OPTIONS MENU", 20, 1);
pathprint("INPUT DEVICE");
choice=single_file(options, entries);
switch(choice)
{
/* set the selected option by calling mouse_flag_toggle(). */
/* the definitions of the defined constants are in menu.h */
case 0:
mouse_flag_toggle(KEYBOARD_ONLY);
break;
case 1:
mouse_flag_toggle(MOUSE_ONLY);
break;
case 2:
mouse_flag_toggle(MOUSE_PLUS_KEYBOARD);
break;
default:
break;
}
}
/* menu_options_demo() is the menu for controlling whether the mouse will */
/* be active, and if so, how sensitivie it will be. */
static void menu_options_demo()
{
static char *options[] =
{
"Return to main menu",
"Select menu input option",
"Modify mouse sensitivity"
};
int choice, entries=3;
reset_menu(0);
for(;;)
{
CLS;
print_headline("MENU-CONTROL OPTIONS MENU", 20, 1);
pathprint("MENU OPTIONS");
/* get a menu selection */
choice=single_file(options, entries);
switch(choice)
{
case 0:
CLS;
return;
case 1:
CLS;
input_options();
reset_menu(choice);
break;
case 2:
CLS;
mouse_sensitivity();
reset_menu(choice);
break;
default:
break;
}
}
}
/* mouse_sensitivity() sets the three parameters of menu mouse */
/* responsiveness: SENSITIVITY is the number of mickeys that the mouse must */
/* move in a reading interval in order to be accepted as movement. In */
/* general, this is not an important number. 3 will keep random vibrations */
/* of the desktop from causing a false positive, but you would have to make */
/* the number quite large (say, 50 or more) to make an actual mouse motion */
/* go unnoticed. ON_TIME and OFF_TIME are the more critical parameters. */
/* together they define a mouse gated duty cycle. ON_TIME is the length */
/* of time in seconds that the mouse is "active", i.e., how long you wait */
/* before seeing whether the mouse has moved more than SENSITIVITY mickeys. */
/* OFF_TIME is the amount of time between ON_TIME reads of the mouse. The */
/* resolution of the timer is 1/18.2 sec, or about 0.05 sec. So a value of */
/* 0.04 or 0.06 will be the same value. It is important to have a reasonable */
/* amount of OFF_TIME, so the user gets a "positive feel" when selecting a */
/* menu item. If OFF_TIME is too small, the user tends to overshoot his */
/* menu item. */
static void mouse_sensitivity()
{
int sensitivity;
double on_time, off_time;
char string[80];
CLS;
printf("Enter the movement threshold in mickeys (default = 3)\n");
if(strlen(mgets(string)))
sensitivity=atoi(string);
else /* carriage return keeps defaults */
sensitivity=3;
printf("\nEnter the active part of the mouse duty cycle (default = 0.05 sec)\n");
if(strlen(mgets(string)))
on_time=atof(string);
else
on_time=0.05;
printf("\nEnter the inactive part of the mouse duty cycle (default = 0.15 sec)\n");
if(strlen(mgets(string)))
off_time=atof(string);
else
off_time=0.15;
/* set the new values */
menu_mouse_config(sensitivity, on_time, off_time);
}
/* single_file() is a front-end for menu() calls when I want to have */
/* a single row of menu selection items using alphabetical selection */
/* and double-space between entries */
static int single_file(options, entries)
char *options[];
int entries;
{
int top, left, tab, columns, spacing, auto_label;
int choice; /* menu selection variable */
/* initialize menu variables */
top=5; /* begin menu fields at line 5 */
left=20; /* space in 20 characters to center the menu */
tab=0; /* TAB is meaningless with one column. */
columns=1;
spacing=2; /* double space between the menu entries */
auto_label= -2;